<template>
  <!-- 面板组件测试 -->
  <HomePanel ref="RefHot" title="人气推荐" sub-title="人气爆款 不容错过">
    <template #default>
       <ul ref="pannel" class="goods-list">
        <li v-for="item in list" :key="item.id">
          <RouterLink to="/">
            <img v-ImgLazy="item.picture" alt="" />
            <p class="name">{{ item.title }}</p>
            <p class="desc">{{ item.alt }}</p>
          </RouterLink>
        </li>
      </ul>
    </template>
  </HomePanel>
</template>
<script>
import { useObserver } from '@/compositions'
import { findHot } from '@/api/home'
import HomePanel from '@/views/Home/components/home-panel'
import { ref } from 'vue'
export default {
  name: 'HomeHot',
  components: {
    HomePanel
  },
  setup () {
    const list = ref([])
    async function hGetList () {
      const res = await findHot()
      list.value = res.result
    }
    const { RefHot } = useObserver(hGetList)
    // const RefHot = ref(null)
    // const { stop } = useIntersectionObserver(
    //   RefHot,
    //   ([{ isIntersecting }], observerElement) => {
    //     if (isIntersecting) { // isIntersecting状态是到达可视区为true其他区域false
    //       stop() // 只调用一次,这个useIntersectionObserver方法就不执行了
    //       hGetList() // 调用接口
    //     }
    //   })
    return {
      list,
      RefHot
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
    &:hover {
      transform: translateY(-5px);
      transition: all 0.3s;
      box-shadow: 0px 5px 10px 1px rgba(0, 0, 0, 0.3);
    }
  }
}
</style>
